#!/bin/bash
echo "IMAGE_NAME:${IMAGE_NAME}"
echo "PROJECT_CODE:${PROJECT_CODE}"
echo "project_dir:${project_dir}"

case_num=$1     # 用例序号
case_id=$2      # 用例id
case_detail=$3  # 用例描述
case_run_script=$4  # 用例执行脚本
case_remove_scripts=$5  # 资源释放脚本
run_performance=$6  # 是否执行性能用例 0不执行/1执行
run_precision=$7    # 是否执行精度用例 0不执行/1执行
code_version=$8     # 代码版本

fail=0
fail_case=""

echo "==================== ${case_num}: 执行${case_detail}用例-${case_id} ===================="
echo "==================== 开始执行，执行时间: $(date -u +"%Y%m%d-%H:%M:%S" --date='+8 hours') ===================="
start_time=$(date +%s)
# 冒烟用例启动脚本
bash ${case_run_script} ${case_id} ${run_performance} ${run_precision} ${code_version}
ret_code=$?
if [ $ret_code -ne 0 ]; then
	echo "${case_num}: ${case_id} 任务失败！！！ ret_code: ${ret_code}"
	echo "==================== 清理资源"
	bash ${case_remove_scripts} ${case_id} || true
	fail_case="${fail_case} ${case_num}"
	echo "清理完成"
else
	echo "${case_num}: ${case_id} 任务成功！！！"
	echo "==================== 清理资源"
	bash ${case_remove_scripts} ${case_id} || true
	echo "清理完成"
fi
end_time=$(date +%s)
elapsed=$((end_time - start_time))
echo "==================== ${case_num} 执行完成, 结束时间: $(date -u +"%Y%m%d-%H:%M:%S" --date='+8 hours'), 执行耗时: ${elapsed} 秒 ===================="
fail=$((fail + ret_code))
echo "sleep 30 second"
sleep 30
exit $fail
